<template>
	<div class="aid">
		<div class="base">
			<p class="fixed-top">
				{{ JSON.stringify(text) == '{}' ? '添加组织年审' : '修改组织年审审批状态' }}
				<a-icon @click="closeFunction" type="close" />
			</p>
			<div class="main" id="new_message">
				<a-form :form="form">

					<a-form-item label="是否通过">
						<a-radio-group name="radioGroup" @change="radioChange"
							v-decorator="['state', { rules: [{ required: true, message: '请选择是否通过' }] }]">
							<a-radio :value="3">是</a-radio>
							<a-radio :value="2">否</a-radio>
						</a-radio-group>
					</a-form-item>
					<a-form-item label="审核意见">
						<a-input type="textarea" :auto-size="global.textareaHeight"
							v-decorator="['reason',{ rules: [{ required:requireMust, message: '请输入审核意见' }] }]" />
					</a-form-item>

					<a-form-item class="fixed-bottom">
						<a-button type="primary" @click="handleSubmit">
							{{ JSON.stringify(text) == '{}' ? '确认添加' : '确认修改' }}
						</a-button>
						<a-button style="margin-left: 10px;" @click="closeFunction">取消</a-button>
					</a-form-item>
				</a-form>
			</div>
		</div>
	</div>
</template>

<script>
	import moment from 'moment';
	import {
		ManageClubAnnualAuditDoAdd,
		ManageClubClubAnnualAuditDoUpdateState
	} from '@/api/follow';
	export default {
		props: {
			text: Object
		},
		watch: {
			text: function(text) {
				let that = this;
				if (JSON.stringify(text) == '{}') {
					that.currentID = ''

				} else {
					that.currentID = text.ID;
					setTimeout(function() {
						text.dataTime = [that.moment(text.ApplyStartTime), that.moment(text.ApplyEndTime)]
						that.form.setFieldsValue({
							dataTime: text.dataTime,
							Name: text.Name,
							IsEnable: text.IsEnable,
							Content: text.Content
						})


					}, 300);
				}
			}
		},
		data() {
			return {
				requireMust: false,
				loading: false,
				formLayout: 'horizontal',
				form: this.$form.createForm(this, {
					name: 'coordinated'
				}),
				currentID: '',
				UserList: []
			};
		},
		methods: {
			moment,
			closeFunction(data) {
				this.form.resetFields();
				this.$emit('closeFun', data);
			},
			ondataChange(value, dateString) {},
			onOk(value) {
				// console.log('onOk: ', value);
			},
			radioChange(e) {
				if (e.target.value == 2) {
					this.requireMust = true
				} else {
					this.requireMust = false;
				}
			},
			handleSubmit(e) {
				this.form.validateFields(async (err, values) => {
					if (!err) {
						let data = {};
						data = values;
						data.clubID = this.text.ClubID
						let successNum = 0,
							errorList = [],
							that = this;
						let res = {};
						if (!this.currentID) {
							res = await ManageClubAnnualAuditDoAdd(data);
						} else {
							console.log(this.text.textArr)
							if (this.text.textArr && this.text.textArr.length > 0) {
								for (let i = 0; i < this.text.textArr.length; i++) {
									data.clubAnnualAuditID = this.text.textArr[i].ID
									data.clubID = this.text.textArr[i].ClubID
									res = await ManageClubClubAnnualAuditDoUpdateState(data);
									if (res.data.code == 0) {
										successNum++
									} else {
										errorList.push(this.text.textArr[i].Name || this.text.textArr[i]
											.Name)
									}
								}
								const h = this.$createElement;
								this.$info({
									title: '审核结果',
									content: h('div', {}, [
										h('p', `成功审核了${successNum}条数据`),
										h('p', errorList.length > 0 ?
											`失败了${errorList.length}条数据，失败的活动为${errorList.join(',')}` :
											'')
									]),
									onOk() {
										// that.$info.onCancel()
										that.closeFunction('1');
									}
								});
								// this.$message.success('已完成');
								// this.closeFunction('1');
							} else {
								data.clubAnnualAuditID = this.currentID;
								res = await ManageClubClubAnnualAuditDoUpdateState(data);
							}

						}
						if (res.data.code === 0) {
							this.$message.success(res.data.msg);
							this.closeFunction('1');
						} else {
							this.$message.error(res.data.msg);
						}
					}
				});
			}
		}
	};
</script>

<style lang="less" scoped>
	/deep/.ant-form {
		margin-top: 50px;
		padding-bottom: 50px;
	}

	/deep/.ant-form-item {
		margin: 20px 50px;
		display: flex;
	}

	/deep/.ant-form-item-label {
		width: 100px;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
		text-align: right;
	}

	/deep/.ant-form-item-control-wrapper {
		flex: 1;
	}

	/deep/.ant-calendar-picker {
		width: 100% !important;
	}

	.ant-upload-list-picture-card-container {
		width: 80px;
		height: 80px;
	}
</style>
